'use strict';

module.exports = {

  async up (queryInterface, Sequelize) {
    const { INTEGER, STRING, DATE, TEXT } = Sequelize;
    await queryInterface.createTable('moment',{
      id:{
        type: INTEGER(20).UNSIGNED, 
        primaryKey: true, 
        autoIncrement:true
      },
      content: {
        type: TEXT,
        allowNull: false,
        defaultValue: '',
        comment: "朋友圈内容"
      },
      image: {
        type: TEXT,
        allowNull: false,
        defaultValue: '',
        comment: "朋友圈图片"
      },
      video: {
        type: STRING,
        allowNull: false,
        defaultValue: '',
        comment: "朋友圈视频"
      },
      location: {
        type: STRING,
        allowNull: false,
        defaultValue: '',
        comment: "位置"
      },
      remind: {
        type: STRING,
        allowNull: false,
        defaultValue: '',
        comment: "提醒谁看 用户id"
      },
      see: {
        type: STRING,
        allowNull: false,
        defaultValue: 'all',
        comment: "谁可以看 all公开 none 私密 only:  指定人看见 except:  谁不可以看"
      },
      user_id: {
        type: INTEGER(20).UNSIGNED, 
        allowNull: false, 
        comment: '用户id',
        // 定义外键
        references: {
          model: 'user',  // 对应表名称
          key: 'id' // 对应表的主键
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      created_at: DATE,
      updated_at: DATE
    });
  },
  // 回滚
  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('moment');
  }
};
